<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="姓名" prop="clockUserName">
        <el-input
          v-model="queryParams.clockUserName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--
      <el-form-item label="联系方式" prop="clockUserName">
        <el-input
          v-model="queryParams.clockUserName"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
-->

      <el-form-item label="打卡类型" prop="clockType">
        <el-select
          v-model="queryParams.clockType"
          placeholder="请选择打卡类型"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in this.getDictDatas(DICT_TYPE.CLASS_CLOCK_TYPE)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="打卡状态" prop="clockStatus">
        <el-select
          v-model="queryParams.clockStatus"
          placeholder="请选择打卡状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in this.getDictDatas(
              DICT_TYPE.ACCOMMODATION_CLOCK_STATUS
            )"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain  @click="handleAdd"
                   v-hasPermi="['study:clock-record:create']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain  @click="handleExport" :loading="exportLoading"
                   v-hasPermi="['study:clock-record:export']">导出</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="primary" plain @click="showFeatures = true"
          >请假设置</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain @click="showAudit = true"
          >请假审核</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <!-- <el-table-column label="主键" align="center" prop="id" /> -->
      <!-- <el-table-column label="上课时间ID" align="center" prop="studyTimeId" /> -->
      <el-table-column label="学院" align="center" prop="collegeName" />
      <el-table-column label="系部" align="center" prop="departmentName" />
      <!-- <el-table-column label="星期" align="center" prop="weekId" /> -->
      <el-table-column label="班级" align="center" prop="className" />
      <el-table-column label="角色" align="center" prop="clockRole">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.COLLEGE_USER_ROLE"
            :value="scope.row.clockRole"
          />
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="clockUserName" />
      <!-- <el-table-column label="课程ID" align="center" prop="subjectId" /> -->
      <el-table-column label="基准打卡" align="center" prop="standardTime" />
      <el-table-column label="教室名称" align="center" prop="roomName" />
      <el-table-column
        label="打卡时间"
        align="center"
        prop="clockTime"
        width="165"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.clockTime) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="打卡类型" align="center" prop="clockType">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.CLASS_CLOCK_TYPE" :value="scope.row.clockType" />
        </template>
      </el-table-column> -->
      <el-table-column label="打卡结果" align="center" prop="clockStatus">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.ACCOMMODATION_CLOCK_STATUS"
            :value="scope.row.clockStatus"
          />
        </template>
      </el-table-column>
      <!-- <el-table-column label="教师信息" align="center" prop="teacherId" /> -->
      <!-- <el-table-column label="打卡备注" align="center" prop="clockRemark" /> -->
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column> -->
      <!--      <el-table-column-->
      <!--        label="操作"-->
      <!--        align="center"-->
      <!--        class-name="small-padding fixed-width"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-edit"-->
      <!--            @click="handleUpdate(scope.row)"-->
      <!--            v-hasPermi="['study:clock-record:update']"-->
      <!--            >修改-->
      <!--          </el-button>-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-delete"-->
      <!--            @click="handleDelete(scope.row)"-->
      <!--            v-hasPermi="['study:clock-record:delete']"-->
      <!--            >删除-->
      <!--          </el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加修改组件 -->
    <form-edit
      :show.sync="open"
      :title="title"
      @success="getList"
      ref="editDialog"
    ></form-edit>
    <features :show.sync="showFeatures" />
    <audit :show.sync="showAudit" />
  </div>
</template>

<script>
import {
  createClockRecord,
  updateClockRecord,
  deleteClockRecord,
  getClockRecord,
  getClockRecordPage,
  exportClockRecordExcel
} from "@/api/study/clockRecord";
import formEdit from './formEdit'
import features from './features.vue'
import audit from './audit.vue'

import CollegeSelector from "@/components/CollegeSelector";
import ProfessionsSelector from "@/components/ProfessionsSelector";
import ClassesFromSelector from "@/components/ClassesFromSelector";
import DepartmentsSelector from "@/components/DepartmentsSelector";
import WeekListSelector from "@/components/WeekListSelector";
import TeacherSelector from "@/components/TeacherSelector";

export default {
  name: "ClockRecord",
  components: {
    TeacherSelector,
    WeekListSelector,
    formEdit,
    features,
    audit,
    CollegeSelector,
    ProfessionsSelector,
    ClassesFromSelector,
    DepartmentsSelector
  },
  data() {
    return {
      showAudit: false,
      tags: [
        { name: '标签一', type: '' },
        { name: '标签二', type: '' },
        { name: '标签三', type: '' },
        { name: '标签四', type: '' },
        { name: '标签五', type: '' }
      ],
      showFeatures: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 打卡记录列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        clockType: null,
        clockUserName: null,
        clockStatus: null,
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getClockRecordPage(this.queryParams).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 表单重置 */
    reset() {
      this.form = {
        clockType: undefined,
        clockUserName: undefined,
        clockStatus: undefined,
      };
      this.resetForm("form");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {

      this.open = true;
      this.title = "添加打卡记录";
      this.$refs.editDialog.initData({});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {

      const id = row.id;
      getClockRecord(id).then(response => {
        let form = response.data;
        this.open = true;
        this.title = "修改打卡记录";
        this.$refs.editDialog.initData(form);
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除打卡记录编号为"' + id + '"的数据项?').then(function () {
        return deleteClockRecord(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal.confirm('是否确认导出所有打卡记录数据项?').then(() => {
        this.exportLoading = true;
        return exportClockRecordExcel(params);
      }).then(response => {
        this.$download.excel(response, '打卡记录.xls');
        this.exportLoading = false;
      }).catch(() => {
      });
    }
  }
};
</script>
